from django.contrib.auth.models import User
from django.db import models

normal_length = 100
long_length = 400


# Create your models here.

class Team(models.Model):
    id = models.AutoField(primary_key=True)
    admin = models.OneToOneField(User, on_delete=models.CASCADE)
    website = models.CharField(max_length=100, blank=True, null=True)
    name = models.CharField(max_length=100, blank=True)
    intro = models.CharField(max_length=500, blank=True, null=True)
    logo = models.ImageField(blank=True, default='team/logo/default.png')
    email = models.CharField(max_length=100, blank=True, null=True)
    regTime = models.DateTimeField(auto_now_add=True)

class TeamPhoto(models.Model):
    team = models.ForeignKey(Team,on_delete=models.CASCADE)
    photo = models.ImageField(blank=True, upload_to='team/photo/',default='team/photo/default.png')
    photoIntro = models.TextField(max_length=40,default="照片介绍")


class UserInfo(models.Model):
    typeChoices = [(0, '超级用户'), (1, '标准用户'), (2, '团队管理员'), (3, '团队成员')]
    statusChoices = [(0, '未激活'), (1, '正常'), (2, '被封禁')]
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    name = models.CharField(max_length=20, blank=True, null=True)
    nick = models.CharField(max_length=20, blank=True, null=True)
    phone = models.CharField(max_length=20, blank=True)
    avatar = models.ImageField(upload_to="avatar", blank=True, default="avatar/default.png")
    intro = models.TextField(max_length=500, blank=True)
    type = models.IntegerField(choices=typeChoices)
    regTime = models.DateTimeField(auto_now_add=True)
    lastLogin = models.DateTimeField(auto_now=True)
    status = models.IntegerField(choices=statusChoices, default=1)
    teamTo = models.ForeignKey(Team, on_delete=models.CASCADE, blank=True, null=True)
    courses = models.ManyToManyField('course.Course', related_name='Join', blank=True)
    fav = models.ManyToManyField('course.Course', related_name='Favorite', blank=True)
